home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)buf_rebind.c V1.18 3/22/95";
- #endif
-
- /*
- | file name - buf_rebind.c
- |===================================================================
- |
- | This program is an example of how you might get data into your
- | views without using the data source facility. The method
- | is called Rebinding. This method creates a link between the
- | variable descriptors (vdps) associated with the dynamic
- | objects and program variables.
- |
- | In this way, the program variables are the source of data
- | for the variable descriptors rather than the data source
- | variables.
- |
- | Typing a <q|Q> or the right mouse button will exit the program.
- |
- |===================================================================
- */
-
- /* DV-Tools header files */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VGfundecl.h" /* VG routines (get info from dgp & vdp) */
- #include "GRfundecl.h" /* GR routines (interface to display device)
-
- #include <windows.h>
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "buffer.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define DRAWING_VIEWPORT (RECTANGLE *)NULL
-
- /*
- * Declare the buffers to which the variable descriptors will be
- * rebound and receive their data.
- */
- LOCAL char TextBuf[80]; /* program buffer for vdp named "Text Var" */
- LOCAL float FloatBuf; /* program buffer for vdp named "Float Var" */
- LOCAL int counter = 0; /* init counter used in UpdateData routine */
-
- /* Local forward function declarations */
- LOCAL ADDRESS RebindVdps V_P_((OBJECT data_obj, ADDRESS vdp, ADDRESS argblock));
- LOCAL void UpdateData V_P_((void));
-
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
- /*
- * program arguments
- * argv[1] - display device (default is DVDEVICE)
- */
-
- /* Define & initialize device name and view filename */
- char *device_name = DVDEVICE; /* default device name */
- char *view_name = VIEW_NAME; /* default view name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- DRAWPORT drawport; /* how & where to display picture, picture frame */
- VIEW view; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location; /* the event representation */
-
- /* Other variables */
- OBJECT drawing; /* graphical representation of screen */
- int Quit = NO; /* flag to quit program */
-
- /*-----------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- make_argv(&argc,&argv,GetCommandLine());
- TInit( DVPATH, DISPFORMS_STB );
-
- /*
- * TscOpenSet: opens a device as a screen object using
- * specified attributes
- *
- * Set exposure block to YES to insure the window
- * is ready for drawing when TdpDraw is called.
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS | V_EXPOSE | V_RESIZE,
- (ULONG) 0);
-
- /*
- * TviLoad: Load a view in from a file,
- * user supplied view or default view of buffer.v
- */
- view = TviLoad (view_name);
- if (!view)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name);
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * TviGetDrawing: Gets a view's drawing object
- * TobForEachVdp: Traverses all variable descriptors
- * in an object
- *
- * Traverse all variable descriptors in the drawing object
- * call the function RebindVdps for each variable descriptor.
- */
- drawing = TviGetDrawing (view);
- TobForEachVdp (drawing, RebindVdps, (ADDRESS) NULL);
-
- /*
- * TdpCreate: Create a drawport.
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- *
- * UpdateData: Update internal buffers used by dynamic
- * objects in view.
- */
- drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
- UpdateData ();
-
- /*
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDraw: Draw the contents of the drawport
- */
- TscErase (screen);
- TdpDraw (drawport);
-
- /*--------------------
- * Control loop
- *
- * Poll the event queue for locator events. If the key
- * represents the character 'q' or 'Q' or the right
- * mouse button then quit the program. Meanwhile,
- * continue to update the data buffers and draw the
- * next iteration of the drawport.
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- * The polling mode used is V_WAIT.
- * Therefore, VOloWinEventPoll does not
- * return until a masked event is
- * generated. V_WAIT always produces
- * a valid location object.
- */
- location = VOloWinEventPoll (V_WAIT);
-
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- */
- TscReset (screen);
- break;
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- *
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
-
- default:
- /*
- * TdpDrawNext: Update all dynamic objects within a
- * drawport's view.
- * Update internal data buffers and draw next iteration
- */
- UpdateData ();
- TdpDrawNext (drawport);
- break;
- }
- break;
-
- case V_BUTTONPRESS:
- /*
- * VOloButton: Returns the button that was pressed
- *
- * The right mouse button exits the program.
- */
- if (VOloButton (location) == 3)
- Quit = YES;
- else
- {
- /*
- * TdpDrawNext: Update all dynamic objects within a
- * drawport's view.
- * Update internal data buffers and draw next iteration
- */
- UpdateData ();
- TdpDrawNext (drawport);
- }
- break;
-
- default:
- break;
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
-
- }
-
- /*--------------------
- * Termination
- *
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDestroy: Destroy the drawport,
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscCloseCurrentScreen: Close the current display screen
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TscErase (screen);
- TdpDestroy (drawport);
- TviDestroy (view);
- TscCloseCurrentScreen ();
- TTerminate ();
- return EXIT_OK;
- }
-
-
- /*
- *-------------
- * RebindVdps -- modify the variable descriptor to use
- * our own program variable as the memory buffer.
- * The variable descriptor which had previously
- * pointed to a data source variable for the data
- * will now look at our program variable for the
- * data information.
- *
- * The parameter data_obj represents the object that
- * the variable descriptor is attached to.
- */
- /*ARGSUSED*/
- LOCAL ADDRESS
- RebindVdps (data_obj, vdp, argblock)
- OBJECT data_obj;
- ADDRESS vdp;
- ADDRESS argblock;
- {
- char *name; /* variable descriptor name */
-
- /*
- * VGvdvarname: Gets a pointer to the variable name
- *
- * The name of the variable descriptor is used to
- * determine which buffer to rebind to. If the
- * variable does not have a name then return.
- */
- name = VGvdvarname (vdp);
- if (!name)
- return V_CONTINUE_TRAVERSAL;
-
- /*
- * TvdPutBuffer: Sets a new variable descriptor buffer
- *
- * Rebind variable descriptor pointer to internal program
- * variable. Program variable will be updated for
- * dynamic objects.
- */
- if (strcmp (name, "Text Var") == 0)
- TvdPutBuffer (vdp, TextBuf);
- else if (strcmp (name, "Float Var") == 0)
- TvdPutBuffer (vdp, (ADDRESS) &FloatBuf);
-
- return V_CONTINUE_TRAVERSAL;
- }
-
-
- /*
- *-------------
- * UpdateData -- updates the values in the buffers of the
- * dynamic elements of the view.
- */
- LOCAL void
- UpdateData ()
- {
- LOCAL char *mycharbuf[] =
- {
- "1st time",
- "2nd time",
- "3rd time",
- "4th time",
- "5th time",
- "6th time",
- "7th time",
- "8th time",
- "9th time",
- "10th time"
- };
-
- /*
- * Increment the counter by one, copy the character string
- * based on the counter value to the program buffer TextBuf.
- */
- if (++counter > 10)
- counter = 1;
-
- strcpy (TextBuf, mycharbuf[counter-1]);
-
- /*
- * Set the program variable FloatBuf by incrementing it's
- * current value by .1. Reset FloatBuf to zero when the
- * the counter has been reset.
- */
- if (counter == 1)
- FloatBuf = 0.0;
- else
- FloatBuf += 0.1;
- }
-